﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WEPMlibrary_Model;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace WEPMconnection_DAL
{
    public class ReviewDAL
    {
        string strSql = ConfigurationManager.ConnectionStrings["Connection"].ToString();
        /// <summary>
        /// 显示项目信息
        /// </summary>
        /// <returns></returns>
        public List<Project> ShowProject()
        {
            List<Project> list = new List<Project>();
            try
            {
                string Sql = "SELECT p.ProjectName,p.YesAccredit,p.DeclareTime,p.Area,p.ProjectState,ui.Name, p2.ProjectTType FROM Project AS p INNER JOIN UserInfor AS ui ON p.Uid=ui.Id INNER JOIN Projectsypes AS p2 ON p.Tid=p2.id";
                SqlDataAdapter Apter = new SqlDataAdapter(Sql, strSql);
                DataTable Dt = new DataTable();
                Apter.Fill(Dt);

                foreach (DataRow item in Dt.Rows)
                {
                    Project p = new Project();
                    p.Area = item["Area"].ToString();
                    p.DeclareTime = Convert.ToDateTime(item["DeclareTime"]).ToString("hh:mm");
                    p.ProjectName = item["ProjectName"].ToString();
                    p.ProjectState = item["ProjectState"].ToString();
                    p.ProjectType = item["ProjectTType"].ToString();
                    p.YesAccredit = item["YesAccredit"].ToString();
                    p.Name = item["Name"].ToString();
                    list.Add(p);
                }
            }
            catch
            {
                throw;

            }
            finally
            {

            }
            return list;
        }
        /// <summary>
        /// 查看信息
        /// </summary>
        /// <returns></returns>
        public List<Message> ShowMessage()
        {
            List<Message> list = new List<Message>();
            try
            {
                string Sql = "SELECT m.Id,m.MessageContent,ui.Name FROM [Message] AS m INNER JOIN UserInfor AS ui ON m.Uid=ui.Id";
                SqlDataAdapter Apter = new SqlDataAdapter(Sql, strSql);
                DataTable Dt = new DataTable();
                Apter.Fill(Dt);

                foreach (DataRow item in Dt.Rows)
                {
                    Message m = new Message();
                    m.Id = Convert.ToInt32(item["Id"]);
                    m.MessageContent = item["MessageContent"].ToString();
                    m.Name = item["Name"].ToString();
                    list.Add(m);
                }
            }
            catch
            {
                throw;

            }
            finally
            {

            }
            return list;
        }


    }
}
